﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using MyOA.BLL;
using MyOA.Model;
using AjaxControlToolkit;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace MyOA.UI.ScheduleManage.DepartSchedule
{
    /// <summary>
    /// DepartScheduleService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class DepartScheduleService : System.Web.Services.WebService
    {
        DepartScheduleManage manage = new DepartScheduleManage();
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public CascadingDropDownNameValue[] getBranch(string knownCategoryValues, string category)
        {
            IList<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

            
            
            //一定要用AjaxControlToolkit.CascadingDropDown才有ParseKnownCategoryValuesString方法
           
            //最开始的级联菜单不用
            // StringDictionary keyValue = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

            IList<BranchInfo> branchInfo = manage.getAllBranchInfo();

            foreach (BranchInfo branch in branchInfo)
            {
                values.Add(new CascadingDropDownNameValue(branch.BranchName,branch.BranchId.ToString()));
            }


            return values.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] getDepart(string knownCategoryValues, string category)
        {
            IList<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

            //一定要用AjaxControlToolkit.CascadingDropDown才有ParseKnownCategoryValuesString方法
            StringDictionary keyValue = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            int branchId = int.Parse(keyValue["BranchInfo"]);
            IList<DepartInfo> departInfo = manage.getDepartInfoByBranchId(branchId);

            foreach (DepartInfo depart in departInfo)
            {
                values.Add(new CascadingDropDownNameValue(depart.DepartName, depart.DepartId.ToString()));
            }
           

            return values.ToArray();
        }

        [WebMethod]
        public string[] keyWord(string prefixText, int count)
        {
            if (string.IsNullOrEmpty(prefixText) == true || count <= 0) return null;

            IList<string> loginId = manage.getLoginIdByKeyWord(prefixText);
            return loginId.ToArray();
        }
    }
}
